use log::{debug, error};
use serde::Serialize;

use crate::dto::biz_code;
use crate::dto::biz_code::*;
use crate::dto::sys_dto::MemoryDto;
use crate::dto::task::BizTask;
use crate::msghandler::{post, post_common};
use crate::provider::host_provider::{get_cpu, get_disk_list, get_group_list,
                                     get_host, get_memory, get_nets_list, get_process_list, get_user_list};

/// 处理下发的任务
pub fn handle_task(task: BizTask) {
    let code = task.biz_code;
    let msg_id = task.msg_id;
    debug!("执行task:{}-{}",code,msg_id);
    match code {
        HOST_INFO => {
            post_common(msg_id, code, &get_host());
        }
        MEMORY_INFO => {
            post_common(msg_id, code, &get_memory());
        }
        CPU_INFO => {
            post_common(msg_id, code, &get_cpu());
        }
        DISK_INFO => {
            post_common(msg_id, code, &get_disk_list());
        }
        NET_INFO => {
            post_common(msg_id, code, &get_nets_list());
        }
        PROCESS_INFO => {
            post_common(msg_id, code, &get_process_list());
        }
        USER_INFO => {
            post_common(msg_id, code, &get_user_list());
        }
        _ => {
            error!("未识别的业务code:{}-{}",code,msg_id)
        }
    }
}